package com.zyasdk;

//import com.nb.sdk.statitistics2.GoPlay.GPlay;
//import com.nb.sdk.statitistics2.intf.GPStatIntf;
import android.app.Service;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;

import com.zyasdk.util.ZYALogUtils;
import com.zyasdk.util.ServiceUtil;

public class Zservice extends Service {
	ServiceUtil su;
	static boolean getr_is_running = false;
	boolean isCreate = false;
	Zreceiver mZreceiver;

	@Override
	public IBinder onBind(Intent arg0) {
		ZYALogUtils.e("onBind");
		return null;
	}

	@Override
	public void onCreate() {
		ZYALogUtils.e("onCreate");
		su = ServiceUtil.getModel();
		su.init(this);
		isCreate = true;
		super.onCreate();

		IntentFilter filter = new IntentFilter();
		filter.addAction("com.zyasdk.zservice.startcommand");
		mZreceiver = new Zreceiver();
		registerReceiver(mZreceiver,filter);

//		if (!getr_is_running) {
//			ZYALogUtils.e("run getr");
//			getr_is_running = true;
//			new RUtil().r(getApplicationContext());
//		}
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		if (!isCreate) {
			su = ServiceUtil.getModel();
			su.init(this);
			su.sendMyBroadcast("com.zyasdk.zservice.startcommand");
		} else {
			isCreate = false;
		}
		return START_STICKY;
	}

	@Override
	public void onDestroy() {
		// 当服务被杀死之后发送自定义广播
		su.sendMyBroadcast("com.zyasdk.zservice.destroy");
		ZYALogUtils.e("onDestroy");
		super.onDestroy();
	}

}
